package nl.fonfolio.view {
	//import fl.core.UIComponent;	
	
	import nl.fonfolio.controller.Controller;	
	import nl.fonfolio.model.Model;	
	
	import flash.display.*;
	import flash.text.TextField;
	
	import caurina.transitions.Tweener;
	
	import flash.events.MouseEvent;
	import flash.events.Event;
	
 

	

	/**
	 * @author Paul
	 */
	public class Window extends Sprite {

		public var fonfolio : Sprite;
		public var background : MovieClip;
	
		public var widgetcontainer:MovieClip = new MovieClip();
		
		public var close_btn : MovieClip;	
		

		private var model : Model;
		private var controller : Controller;
		
		//text
		//private var dashboardTextBox:TextField = new TextField();
    	
			
		
		
		public function Window(fonfolio:Sprite, model:Model, controller:Controller) 
		{
			var dashboardText:String;
			
			this.controller = controller;
			this.model = model;
			this.fonfolio = fonfolio;
			
			//size vlak
			this.fonfolio.stage.addEventListener(Event.RESIZE, this.onResizeStage);
			this.close_btn.addEventListener(MouseEvent.CLICK, this.close);
		
			//resize
			this.resize();
			this.x = this.fonfolio.stage.stageWidth/2;
			this.y = this.fonfolio.stage.stageHeight/2;
		
			//text
			trace(this.close_btn.y);
			var dashboardTextBox:TextField = createTextField(0-this.width/2, this.close_btn.y+this.close_btn.height, this.width, this.height);
			dashboardText = "helloo, i am lindsay lohan! kl;gs sklfdjgs sfklgjsldkjg lkfg klfdg lkgj";
			dashboardTextBox.textColor = 0xFFFFFF;
			dashboardTextBox.text = dashboardText;
			
			//hide it  //**FIXME kan ik niet aan de breedte komen als hij al gescaled is op een of andere manier? **/
			this.scaleX = 0;
			this.scaleY = 0;
			
			//widgets
			this.createWidgetContainer();
		}
		
 		private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x; 
            result.y = y;
            result.width = width; 
            //result.height = height;
            result.multiline = true;
            result.wordWrap = true;
           // result.border = true;
           // result.borderColor = 0xFFFFFF;
            addChild(result);
            return result;
        }

		private function createWidgetContainer() : void {
			/** drawing widgetcontainer to check if its really there **/
		/*	widgetcontainer.graphics.beginFill(0xFFffff);
			widgetcontainer.graphics.drawRect(0, 0, 100, 5);
			widgetcontainer.graphics.endFill();
			addChild(widgetcontainer);*/
		}

		

		private function onResizeStage(event : Event) : void {
			this.resize();
		}
		
		private function resize() : void {  
		/*	this.background.height = this.fonfolio.stage.stageHeight;*/
			this.x = this.fonfolio.stage.stageWidth/2;
			this.y = this.fonfolio.stage.stageHeight/2;
	
			//this.widgetcontainer.width = this.width;
			//this.widgetcontainer.x = 0;
			//this.widgetcontainer.y = this.height/2 - this.widgetcontainer.height/2 ;
			//this.widgetcontainer.graphics.beginFill(0xFFCC00);
		}

		private function close(event : MouseEvent) : void {
			Tweener.addTween(this, {scaleX:0,scaleY:0, time:0.5, transition:"easeInQuart"});
		}
		
		public function openWindowHandler() : void {
			Tweener.addTween(this, {scaleX:1,scaleY:1, time:1, transition:"easeOutElastic"});
		}
	}
}
